﻿using FlyingHat.Model.Models;
using FlyingHat.Service.IService;
using Microsoft.AspNetCore.Mvc;

namespace FlyingHat.Web.Controllers
{
    /// <summary>
    /// 图书室管理
    /// </summary>
    public class LibraryController : BaseController
    {
        private readonly ILibraryService libraryService;

        public LibraryController(ILibraryService libraryService)
        {
            this.libraryService = libraryService;
        }

        [HttpGet]
        public IActionResult Index()
        {
            return View();
        }

        [HttpGet]
        public async Task<IActionResult> GetList(string? key, int page, int limit)
           => Json(await libraryService.GetList(key, page, limit).ConfigureAwait(false));

        [HttpPost]
        public async Task<IActionResult> AddOrUpdate(ModifyLibraryModel model)
          => Json(await libraryService.AddOrUpdate(model).ConfigureAwait(false));

        [HttpPost]
        public async Task<IActionResult> Delete(long id)
         => Json(await libraryService.Delete(id).ConfigureAwait(false));

    }
}
